<?php
namespace app\admin\controller;
use app\admin\model\User as UserModel;
use app\common\BaseController;
class User extends BaseController
{
	protected  $model;
	protected function initialize()
    {
       $this->model = new UserModel;
      
    }

    public function delete($id){

        if(request()->isAjax() && request()->isGet()){ 
            UserModel::destroy($id);
            return 'success';
        }
    }
	public function index(){
      
        return view('index');
    }
    public function edit(){
      
       if(request()->isPost()){
            if($this->model->save(input(),['id'=>input('id')])){
                $this->redirect('/admin/user');
            }else{
                var_dump(UserModel::$validate->getError());
                return;
            }
       }
       
       if($edit_user = $this->model->Oselect()){
          return view('edit',['edit_user'=>$this->model->Oselect()]);
       }
        else
            return '404 error';
    }

    public function login()
    {
        
        if(request()->isAjax() && request()->isPost()){ 
            return $this->model->login();
        }
        return view('login');
    }

    public function register(UserModel $UserModel){

    	if(request()->isAjax() && request()->isPost()){
            return $this->model->register();
        }
        return view('register');
    }
    public function logout(){
        cookie('uid',null);
        $this->redirect('/');
    }
    public function userinfo($id){
        // $this->view->engine->layout('layout/common');
        // $user = UserModel::where('id',$id)->find();
        return view('userinfo');
    }
}

